// $URL: http://mingw-lib.googlecode.com/svn/trunk/working/avcodec_to_widget_8/t_generator.h $
// $Rev: 276 $
// $Author: akio.miyoshi $
// $Date:: 2010-07-25 05:58:05 +0000#$

#ifndef T_GENERATOR_H
#define T_GENERATOR_H

#include "stable.h"

////class Widget;
////class T_Box_Player_Context;
class T_Generator : public QIODevice
{
    Q_OBJECT
public:
    class T_Box_Player_Context *m_player_ctx;
    qint64 m_out_read_size;
    qint64 m_max_seek_size;
    QByteArray m_audio_data_left;
    QByteArray m_audio_last_read;
    qint64 m_base_bytes;
    qint64 m_base_msecs;
    T_Generator(class T_Box_Player_Context *a_player_ctx, QObject *parent)
        : QIODevice(parent)
        , m_player_ctx(a_player_ctx)
        , m_out_read_size(0)
        , m_max_seek_size(0)
        , m_base_bytes(0)
        , m_base_msecs(-1)
    {
        bool v_ok = QIODevice::open(QIODevice::ReadOnly);
        qDebug() << "[Generator::Generator()]" << v_ok;
    }
    ~T_Generator()
    {
        qDebug() << "[Generator::~Generator()]";
    }
    virtual qint64 bytesAvailable() const
    {
        qDebug() << "[Generator::bytesAvailable()]";
        return 0;
    }
    virtual qint64 writeData(const char *data, qint64 len)
    {
        qDebug() << "[Generator::writeData()]";
        Q_UNUSED(data);
        Q_UNUSED(len);
        return 0;
    }
    virtual qint64 readData(char *data, qint64 maxlen);
    virtual bool seek(qint64 pos);
    qint64 elapsed();
    void breakTimer();
protected:
    //QByteArray p_readPacket(qint64 wanted_len);
    QByteArray p_readPacket(qint64 prec_len, qint64 need_len);
    QByteArray p_pop_front(QByteArray &a_bytes, int a_maxlen);
    QByteArray p_pop_back(QByteArray &a_bytes, int a_maxlen);
};

#endif // T_GENERATOR_H
